<template>
  <div class="personInfo" id="personInfoId">
    <h2>个人信息：</h2>
    <el-card shadow="always">
      <el-form
        label-position="top"
        status-icon
        label-width="80px"
        :model="formLabelAlign"
      >
        <el-row :gutter="100">
          <el-col :span="9" :offset="2">
            <el-form-item label="用户名">
              <el-input v-model="formLabelAlign.userName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9" :offset="1">
            <el-form-item label="密码">
              <el-input
                v-model="formLabelAlign.password"
                type="password"
                autocomplete="off"
                show-password
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="100">
          <el-col :span="9" :offset="2">
            <el-form-item label="电话">
              <el-input v-model="formLabelAlign.phone" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9" :offset="1">
            <el-form-item label="性别">
              <el-select
                v-model="formLabelAlign.userSex"
                placeholder="还没有性别"
                style="width: 100%"
              >
                <<<<<<< HEAD
                <el-option label="男" :value="Sex1"></el-option>
                <el-option label="女" :value="Sex2"></el-option>
                <el-option label="保密" :value="Sex3"></el-option>
                =======
                <el-option label="男" :value="1"></el-option>
                <el-option label="女" :value="2"></el-option>
                <el-option label="保密" :value="3"></el-option>
                >>>>>>> 688c9ba774507813de59621648c27ec61b74d280
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="100">
          <el-col :span="9" :offset="2">
            <el-form-item label="校区">
              <el-select
                v-model="formLabelAlign.userAddress"
                placeholder="还没有填写校区"
                style="width: 100%"
              >
                <el-option label="广州" :value="Address1"></el-option>
                <el-option label="三水" :value="Address2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="9" :offset="1">
            <el-form-item label="微信号">
              <el-input v-model="formLabelAlign.userWechat"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="100">
          <el-col :span="9" :offset="2">
            <el-form-item label="邮箱">
              <el-input v-model="formLabelAlign.userEmail"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="9" :offset="1">
            <el-form-item label="学校">
              <el-input
                v-model="formLabelAlign.userSchool"
                disabled
                placeholder="请输入你的学校名称"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row style="margin-top: 50px">
          <el-col :span="5" :offset="9">
            <el-button
              type="primary"
              @click="submitForm('formLabelAlign')"
              style="width: 100%"
              >保存</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <!--      弹出提示框-->
    <el-dialog
      title="提示"
      :visible.sync="centerDialogVisible"
      width="30%"
      center
    >
      <div style="text-align: center">
        <h4>{{ dialogValue }}</h4>
        <span slot="footer" class="dialog-footer">
          <el-button
            type="primary"
            @click="clickButton"
            style="margin-top: 30px"
            >确 定</el-button
          >
        </span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "person-info",
  data() {
    return {
      formLabelAlign: [],
      dialogValue: "",
      centerDialogVisible: false,
      Address1: "广州",
      Address2: "三水",
      Sex1: "男",
      Sex2: "女",
      Sex3: "保密",
    };
  },
  mounted() {
    //  使用生命周期和ajax加载数据
    let jsonObj = new Object();
    jsonObj.userId = window.sessionStorage.getItem("userId");
    let self = this;
    console.log(window.sessionStorage.getItem("userId"));
    $.get(
      "http://waiterxiaoyy.free.idcfengye.com/web/getUserInfoByUserId",
      jsonObj,
      function (data) {
        self.formLabelAlign = data.data[0];
      },
      "json"
    );
    console.log(data);
  },
  methods: {
    submitForm(formName) {
      let self = this;
      if (
        self.formLabelAlign.password != null &&
        self.formLabelAlign.password != ""
      ) {
        self.formLabelAlign.phone = window.sessionStorage.getItem("phone");
        let jsonMsg = JSON.stringify(this.formLabelAlign);

        $.post(
          "http://waiterxiaoyy.free.idcfengye.com/web/updateInfo",
          jsonMsg,
          function (data) {
            if (data.code === 200) {
              self.$message.success(data.msg)
              self.$router.push({
                path: "/",
              });
            } else {
              self.$message.error(data.msg)
            }
            self.centerDialogVisible = true;
          },
          "json"
        );
      } else {
        self.$message.error("密码不能为空");
        return false;
      }
    },
    clickButton() {
      this.centerDialogVisible = false;
    },
  },
};
</script>

<style scoped>
.personInfo {
  width: 80%;
  margin: 0 auto;
  padding-top: 80px;
}
</style>
